﻿#region 命名空间

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using WinnerCMS.BLL;
using WinnerCMS.Model;
using WinnerCMS.Common;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.Gather
{
    /// <summary>
    ///     Main 的摘要说明。
    /// </summary>
    [Access("272002,272003,272004")]
    public partial class Main : WebFactory.PageBase
    {
        private GatherManage _myBll;

        protected byte ModelId;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ModelId = byte.Parse(Request["ModelId"]);
            this._myBll = new GatherManage();
            if (!IsPostBack)
            {
                this.txtKeyWord.Text = Request["KeyWord"];


                BindList(this.PageNavigation1.PageNo);
            }
        }

        private void BindList(int pageNo)
        {
            this.BC_Path.Items.Add(new ListItem(WebConfig.SiteName, ""));
            this.BC_Path.Items.Add(new ListItem("采集任务列表",
                string.Format("Main.aspx?ModelId={0}&PageNo=1", Request["ModelId"])));


            var pp = new PagingParam();
            pp.PageNo = pageNo;
            pp.PageSize = this.PageNavigation1.PageSize;
            this.RPList.DataSource = this._myBll.BindList(this.ModelId, this.txtKeyWord.Text, pp);
            this.RPList.DataBind();

            this.PageNavigation1.RecordCount = pp.RecordCount;
        }


        protected string Change(object ID, object PID, object Name)
        {
            if (PID.ToString() == "0")
            {
                return string.Format("Add.aspx?id={0}&ModelId={1}", ID, Request["ModelId"]);
            }
            return string.Format("RuleNode.aspx?Action=Edit&ID={0}&ModelId={1}", ID, Request["ModelId"]);
        }

        protected string StartUrlLinks(object StartUrl)
        {
            var sb = new StringBuilder();
            foreach (var v in StartUrl.ToString().Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries))
            {
                sb.AppendFormat("<a href=\"{0}\" target=\"_blank\">{0}</a><br />", v);
            }
            return sb.ToString();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Response.Redirect("Main.aspx?ModelId=" + Request["ModelId"] + "&KeyWord=" + this.txtKeyWord.Text);
        }
    }
}